<?php
// +----------------------------------------------------------------------
// | title: 标题注释
// +----------------------------------------------------------------------
// | Author: TZ.Leong
// +----------------------------------------------------------------------
// | Date: 2019/8/19 16:53
// +----------------------------------------------------------------------

namespace app\single\api;


use app\single\model\PayLogModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;

class PlayerPay
{
    public function run($params)
    {
        $data["ret"] = 1;
        $maxValue = $params["max_value"] ?? 0;//最大值
        $limit = $params["limit"] ?? 10000;

        $model = new PayLogModel();
        try {
            $payData = $model->where("id > $maxValue")->limit($limit)->order("id ASC")->select();
        } catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
            return $data;
        }

        $returnData = [];
        foreach ($payData as $row) {
            $row["single_id"] = $row["id"];
            $row["player_id"] = $row["role_id"];
            $row["pay_month"] = date("Ym", $row["pay_time"]);
            $row["master_platform"] = PLATFORM;
            unset($row["id"], $row["role_id"]);
            $returnData[] = $row;
        }

        $data["data"] = $returnData;
        return $data;
    }
}